package cn.kgc.springcloud.openfeign.controller;

import cn.kgc.springcloud.openfeign.entity.Role;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: mosin
 * @version: v1.0  2022/8/18
 */
@RestController
@RequestMapping("p")
public class PermissionController {

    @Value("${server.port}")
    private  Integer port;

    @RequestMapping("t1")
    public String test1(){
        return "permission ok port:"+port;
    }

    // 根据角色id 查询权限信息
    @RequestMapping("t2")
    public String test2(Integer roleId){
        return "permission ok port:"+port+"roleId:"+roleId;
    }

    // 根据权限的id  查询权限信息
    @RequestMapping("t3/{pId}")
    public String test3(@PathVariable Integer pId){
        return "permission ok port:"+port+"roleId:"+pId;
    }

    // 如何接收对象类型的参数
    @RequestMapping("t4")
    public String test4(@RequestBody Role role){
        return "permission ok port:"+port+role;
    }


    @RequestMapping("t5")
    public String test5(Integer[] ids){
        for (Integer id : ids) {
            System.out.println("id = " + id);
        }
        return "permission ok port:"+port;
    }

    //微服务中数据的响应格式
    @RequestMapping("t6")
    public Role test6(Integer id){
        Role role = new Role();
        role.setId(id);
        role.setName("admin");
        return role;
    }


}
